package com.example.chatchatbackend.Controller.sendJob;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.send.SendAdv;
import com.example.chatchatbackend.entity.vo.response.SendAdvVO;
import com.example.chatchatbackend.service.sendJob.SendAdvService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */

@Slf4j
@RestController
@RequestMapping("/api/sendAdv")
public class SendAdvController {

    @Autowired
    private SendAdvService sendSendAdvService;

    @GetMapping
    public RestBean<List<SendAdvVO>> getAll(){
        return RestBean.success(sendSendAdvService.getAll());
    }

    @PostMapping
    public RestBean<SendAdvVO> insertSendAdv(@RequestBody SendAdvVO SendAdvVO){
        SendAdvVO insertSendAdvVO = sendSendAdvService.insertSendAdv(SendAdvVO);
        log.info("insert--SendAdv:{}",insertSendAdvVO);
        return RestBean.success(insertSendAdvVO);

    }


    @PostMapping("/list")
    public RestBean<List<SendAdvVO>> insertSendAdvList (@RequestBody List<SendAdvVO> sendSendAdvs){
        List<SendAdvVO> sendSendAdvList = sendSendAdvService.insertSendAdvList(sendSendAdvs);
        log.info("insert--SendAdvList:{}",sendSendAdvList);
        return RestBean.success(sendSendAdvList);
    }


    @GetMapping("/pageThree")
    public RestBean<IPage<SendAdv>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(sendSendAdvService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<SendAdvVO> updateSendAdv(@RequestBody SendAdvVO sendSendAdvVO){
        return RestBean.success(sendSendAdvService.updateSendAdv(sendSendAdvVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> deleteByIds(@RequestBody List<Integer> ids) {
        sendSendAdvService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/ids")
    public RestBean<List<SendAdvVO>> findByIds(@RequestBody List<Integer> ids){
        List<SendAdvVO> sendSendAdvVOList = sendSendAdvService.findByIds(ids);
        return RestBean.success(sendSendAdvVOList);
    }

    @GetMapping("/title")
    public RestBean<List<SendAdvVO>> findByTitle(@RequestBody String title ){
        List<SendAdvVO> sendSendAdvVOList = sendSendAdvService.findByTitle(title);
        return RestBean.success(sendSendAdvVOList);
    }

}
